package com.cloudsigns.factorymanager2.produce.bean;

import android.text.TextUtils;

import com.cloudsigns.factorymanager2.cusenum.CommonEnum;
import com.cloudsigns.factorymanager2.produce.utils.ParseJson;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class Produce_ProductBean implements Serializable {
    /*生产数量*/
    private int amount;
    /*产品名称*/
    private String name;
    /*图片*/
    List<String> picUrl = new ArrayList<>();
    /*具体规格见图纸 */
    private boolean shapeMap;
    /*产品规格*/
    private ShapeTypeBean shapeType = new ShapeTypeBean();
    /*单位*/
    private String unit;
    /*产品id*/
    private String productId;
    /*产品名称*/
    private String productName;
    /*项目名称*/
    private String projectName;

    private String type;

    private List<WorkPartBean> workPartList = new ArrayList<>();

    /*开始时间*/
    private long beginDate;
    /*工程名称*/
    private String engineeringName;
    /*完成时间*/
    private long finishDate;
    /*编辑人*/
    private String editAccountName;
    /*编辑人id*/
    private String editAccountId;
    /*编辑时间*/
    private long editDate;

    /*工程名称*/
    private CommonEnum.ProduceOrderLevel level;
    /*生产订单Id*/
    private String orderId;

    private CommonEnum.ProduceOrderStatus status;

    public int getAmount() {
        return amount;
    }

    public void setAmount(int amount) {
        this.amount = amount;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List<String> getPicUrl() {
        return picUrl;
    }

    public void setPicUrl(List<String> picUrl) {
        this.picUrl = picUrl;
    }

    public boolean isShapeMap() {
        return shapeMap;
    }

    public void setShapeMap(boolean shapeMap) {
        this.shapeMap = shapeMap;
    }

    public ShapeTypeBean getShapeType() {
        return shapeType;
    }

    public void setShapeType(ShapeTypeBean shapeType) {
        this.shapeType = shapeType;
    }

    public String getUnit() {
        return unit;
    }

    public void setUnit(String unit) {
        this.unit = unit;
    }

    public String getProductId() {
        return productId;
    }

    public void setProductId(String productId) {
        this.productId = productId;
    }

    public String getProductName() {
        return productName;
    }

    public void setProductName(String productName) {
        this.productName = productName;
    }

    public String getProjectName() {
        return projectName;
    }

    public void setProjectName(String projectName) {
        this.projectName = projectName;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public List<WorkPartBean> getWorkPartList() {
        return workPartList;
    }

    public void setWorkPartList(List<WorkPartBean> workPartList) {
        this.workPartList = workPartList;
    }

    public long getBeginDate() {
        return beginDate;
    }

    public void setBeginDate(long beginDate) {
        this.beginDate = beginDate;
    }

    public String getEngineeringName() {
        return engineeringName;
    }

    public void setEngineeringName(String engineeringName) {
        this.engineeringName = engineeringName;
    }

    public long getFinishDate() {
        return finishDate;
    }

    public void setFinishDate(long finishDate) {
        finishDate = finishDate + 24 * 3600 * 1000 - 1;
        this.finishDate = finishDate;
    }

    public String getEditAccountName() {
        return editAccountName;
    }

    public void setEditAccountName(String editAccountName) {
        this.editAccountName = editAccountName;
    }

    public String getEditAccountId() {
        return editAccountId;
    }

    public void setEditAccountId(String editAccountId) {
        this.editAccountId = editAccountId;
    }

    public long getEditDate() {
        return editDate;
    }

    public void setEditDate(long editDate) {
        this.editDate = editDate;
    }

    public CommonEnum.ProduceOrderLevel getLevel() {
        return level;
    }

    public void setLevel(CommonEnum.ProduceOrderLevel level) {
        this.level = level;
    }

    public String getOrderId() {
        return orderId;
    }

    public void setOrderId(String orderId) {
        this.orderId = orderId;
    }

    public CommonEnum.ProduceOrderStatus getStatus() {
        return status;
    }

    public void setStatus(CommonEnum.ProduceOrderStatus status) {
        this.status = status;
    }


    public void parseJsonObject(JSONObject dataJsonObj) throws JSONException {
        if (dataJsonObj.has("amount")) {
            String amountStr = dataJsonObj.getString("amount");
            if (null != amountStr && !TextUtils.isEmpty(amountStr) && !amountStr.equals("null")) {
                setAmount(Integer.parseInt(amountStr));
            }
        }
        if (dataJsonObj.has("beginDate")) {
            String beginDateStr = dataJsonObj.getString("beginDate");
            if (!TextUtils.isEmpty(beginDateStr) && !beginDateStr.equals("null")) {
                setBeginDate(Long.parseLong(beginDateStr));
            }
        }
        if (dataJsonObj.has("engineeringName")) {
            setEngineeringName(dataJsonObj.getString("engineeringName"));
        }
        if (dataJsonObj.has("finishDate")) {
            String finishDateStr = dataJsonObj.getString("finishDate");
            if (!TextUtils.isEmpty(finishDateStr) && !finishDateStr.equals("null")) {
                setFinishDate(Long.parseLong(finishDateStr));
            }
        }
        if (dataJsonObj.has("editAccountName")) {
            setEditAccountName(dataJsonObj.getString("editAccountName"));
        }
        if (dataJsonObj.has("editAccountId")) {
            setEditAccountId(dataJsonObj.getString("editAccountId"));
        }
        if (dataJsonObj.has("editDate")) {
            String editDateStr = dataJsonObj.getString("editDate");
            if (!TextUtils.isEmpty(editDateStr) && !editDateStr.equals("null")) {
                setEditDate(Long.parseLong(editDateStr));
            }
        }
        if (dataJsonObj.has("level")) {
            CommonEnum.ProduceOrderLevel level = ParseJson.parseProdutOrderLevel(dataJsonObj, "level");
            setLevel(level);
        }
        if (dataJsonObj.has("orderId")) {
            setOrderId(dataJsonObj.getString("orderId"));
        }
        if (dataJsonObj.has("picUrl")) {
            String picUrlJsonArrStr = dataJsonObj.getString("picUrl");
            if (null != picUrlJsonArrStr && !picUrlJsonArrStr.equals("null") && !TextUtils.isEmpty(picUrlJsonArrStr)) {
                JSONArray picUrlJsonArr = new JSONArray(picUrlJsonArrStr);
                ArrayList<String> picUrlLs = new ArrayList<String>();
                for (int j = 0; j < picUrlJsonArr.length(); j++) {
                    picUrlLs.add(picUrlJsonArr.getString(j));
                }
                setPicUrl(picUrlLs);
            }
        }
        if (dataJsonObj.has("productId")) {
            setProductId(dataJsonObj.getString("productId"));
        }
        if (dataJsonObj.has("productName")) {
            setProductName(dataJsonObj.getString("productName"));
        }
        if (dataJsonObj.has("projectName")) {
            setProjectName(dataJsonObj.getString("projectName"));
        }
        if (dataJsonObj.has("shapeMap")) {
            setShapeMap(dataJsonObj.getBoolean("shapeMap"));
        }
        if (dataJsonObj.has("shapeType")) {
            JSONObject shapeTypeJsonObj = dataJsonObj.getJSONObject("shapeType");
            if (null != shapeTypeJsonObj) {
                getShapeType().parseObject(shapeTypeJsonObj);
            }
        }
        if (dataJsonObj.has("type")) {
            setType(dataJsonObj.getString("type"));
        }
        if (dataJsonObj.has("unit")) {
            setUnit(dataJsonObj.getString("unit"));
        }
        if (dataJsonObj.has("workPartList")) {
            String workPartListJsonArrStr = dataJsonObj.getString("workPartList");
            workPartList.clear();
            if (null != workPartListJsonArrStr && !workPartListJsonArrStr.equals("null") && !TextUtils.isEmpty(workPartListJsonArrStr)) {
                JSONArray workPartListJsonArr = new JSONArray(workPartListJsonArrStr);
                for (int i = 0; i < workPartListJsonArr.length(); i++) {
                    WorkPartBean workPartBean = new WorkPartBean();
                    JSONObject workPartListJsonObj = (JSONObject) workPartListJsonArr.get(i);
                    workPartBean.parseJson(workPartListJsonObj);
                    workPartBean.setOrderId(this.orderId);
                    workPartBean.setProductId(this.productId);
                    this.workPartList.add(workPartBean);
                }
            }
        }
    }
}
